﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CellsLifeActivity
{
    class MatrixControl
    {
        Cell[,] matrixCell;
        byte[,] matrixByte;

        /// <summary>
        /// The property which give an access to private field matrixChar
        /// </summary>
        public Cell[,] MatrixCell
        {
            get
            {
                return matrixCell;
            }
            set
            {
                matrixCell = value;
            }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="rows">Quantity of matrix rows</param>
        /// <param name="columns">Quantity of matrix columns</param>
        public MatrixControl(int rows, int columns)
        {
            //matrixChar = new char[rows, columns];
            matrixCell = new Cell[rows, columns];
            matrixByte = new byte[rows, columns];
            cIni oIni1 = new cIni(GameLogic.iniName);
            GameLogic.SRet = oIni1.ReadValue("Cells percentage", "CommonCellsPercent", "");
            GameLogic.SRet1 = oIni1.ReadValue("Cells percentage", "PredatoryCellsPercent", "");

            Random randomizer = new Random();
            for (int i = 0; i < matrixByte.GetLength(0); i++)
            {
                for (int j = 0; j < matrixByte.GetLength(1); j++)
                {
                    matrixByte[i, j] = (byte)randomizer.Next(0, 100);
                    if (matrixByte[i, j] <= Convert.ToInt32(GameLogic.SRet))
                    {
                        matrixCell[i, j] = new CommonCell();
                    }
                    else
                        if ((matrixByte[i, j] > Convert.ToInt32(GameLogic.SRet)) &&
                            (matrixByte[i, j] <=(Convert.ToInt32(GameLogic.SRet) +Convert.ToInt32(GameLogic.SRet1))))
                        {
                            matrixCell[i, j] = new PredatoryCell();
                        }
                        else matrixCell[i, j] = new EmptyCell();
                }
            }

        }

        /// <summary>
        /// The method which print the matrix into console window
        /// </summary>
        public void PrintMatrix()
        {
            for (int j = 0; j < matrixCell.GetLength(0); j++)
            {
                for (int i = 0; i < matrixCell.GetLength(1); i++)
                    Console.Write(matrixCell[j, i].DrawCell());
                Console.WriteLine();
            }
        }

    }
}
